﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace BookStore
{
    public partial class NXB_DangNhap : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
        {
            string userName = Login1.UserName;
            userName = userName.ToLower();
            using (var context = new BookStoreEntities())
            {
                var temp = from u in context.aspnet_Users
                           where u.LoweredUserName == userName
                           select u;
                if (temp.Count() == 0)
                    return;
                int count = temp.First().NhaXuatBans.Count();
                if (count == 0)
                {
                    e.Authenticated = false;
                    return;
                }
            }
            e.Authenticated = Membership.ValidateUser(Login1.UserName, Login1.Password);
        }
    }
}